home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / RANDEXP.C < prev    next >
Text File  |  1986-05-18  |  1KB  |  33 lines

  1. /* 1.0  01-22-85 */
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1985        *
  6.  ************************************************************************
  7.  * Computes a sample value from an exponential distribution characterized
  8.  * by unit mean, i.e.,
  9.  *
  10.  *        p(x) = exp(-x)
  11.  *
  12.  * The method is by inversion of the cumulative probability function.  See
  13.  * also
  14.  *
  15.  * Knuth, D. E., FUNDAMENTAL ALGORITHMS, Vol II, "Seminumerical Algorithms"
  16.  * Addison-Wesley Pub. Co.,  page 128.
  17.  *
  18.  */
  19.  
  20. #include "defs.h"
  21. #include "stdtyp.h"
  22.  
  23. /************************************************************************/
  24.     double
  25. randexp()            /* Return an exponentially distributed random
  26.                value with unit mean.            */
  27. /*----------------------------------------------------------------------*/
  28. {
  29.     double log(), random();
  30.  
  31.     return (-log(random()));
  32. }
  33.